{% extends 'base.html' %}

{% block title %}{{ title }} - 教务信息管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>
                <i class="fas fa-user-edit me-2 text-primary"></i>
                {{ title }}
            </h2>
            <a href="{% url 'accounts:profile' %}" class="btn btn-secondary">
                <i class="fas fa-arrow-left me-1"></i>返回个人信息
            </a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-lg-8 col-md-10 mx-auto">
        <div class="card shadow">
            <div class="card-header bg-primary text-white">
                <h5 class="card-title mb-0">
                    <i class="fas fa-edit me-2"></i>
                    编辑个人信息
                </h5>
            </div>
            <div class="card-body">
                <form method="post" novalidate>
                    {% csrf_token %}
                    
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle me-2"></i>
                        <strong>提示：</strong>您只能编辑基本信息，角色和权限由管理员设置。
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label for="username" class="form-label">
                                    <i class="fas fa-user me-1"></i>用户名
                                </label>
                                <input type="text" class="form-control" id="username" value="{{ user.username }}" readonly>
                                <div class="form-text">用户名不可修改</div>
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label for="first_name" class="form-label">
                                    <i class="fas fa-id-card me-1"></i>姓名
                                </label>
                                <input type="text" class="form-control" id="first_name" name="first_name" 
                                       value="{{ user.first_name }}" placeholder="请输入您的姓名">
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label for="email" class="form-label">
                                    <i class="fas fa-envelope me-1"></i>邮箱
                                </label>
                                <input type="email" class="form-control" id="email" name="email" 
                                       value="{{ user.email }}" placeholder="请输入您的邮箱">
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label for="role" class="form-label">
                                    <i class="fas fa-user-tag me-1"></i>角色
                                </label>
                                <input type="text" class="form-control" id="role" 
                                       value="{{ user_profile.get_role_display }}" readonly>
                                <div class="form-text">角色由管理员设置</div>
                            </div>
                        </div>
                    </div>
                    
                    {% if user_profile.college_name %}
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label for="college_name" class="form-label">
                                    <i class="fas fa-university me-1"></i>学院名称
                                </label>
                                <input type="text" class="form-control" id="college_name" 
                                       value="{{ user_profile.college_name }}" readonly>
                                <div class="form-text">学院信息由管理员设置</div>
                            </div>
                        </div>
                    </div>
                    {% endif %}
                    
                    <div class="card mt-4">
                        <div class="card-header bg-light">
                            <h6 class="card-title mb-0">
                                <i class="fas fa-info-circle me-2"></i>
                                账号信息
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="info-item mb-3">
                                        <label class="form-label text-muted">
                                            <i class="fas fa-calendar-alt me-1"></i>注册时间
                                        </label>
                                        <div class="info-value">{{ user.date_joined|date:"Y年m月d日 H:i" }}</div>
                                    </div>
                                </div>
                                
                                <div class="col-md-6">
                                    <div class="info-item mb-3">
                                        <label class="form-label text-muted">
                                            <i class="fas fa-clock me-1"></i>最后登录
                                        </label>
                                        <div class="info-value">
                                            {% if user.last_login %}
                                                {{ user.last_login|date:"Y年m月d日 H:i" }}
                                            {% else %}
                                                从未登录
                                            {% endif %}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="d-grid gap-2 d-md-flex justify-content-md-end mt-4">
                        <a href="{% url 'accounts:profile' %}" class="btn btn-secondary me-md-2">
                            <i class="fas fa-times me-1"></i>取消
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save me-1"></i>保存更改
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<style>
.info-item {
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
}

.info-item:last-child {
    border-bottom: none;
}

.info-value {
    font-size: 1.1rem;
    font-weight: 500;
    color: #333;
}
</style>
{% endblock %}